package com.order.role.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.role.domain.OrderRole;
import com.order.role.service.IOrderRoleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 角色管理Controller
 * 
 * @author huhu
 * @date 2020-08-20
 */
@Controller
@RequestMapping("/order/role")
public class OrderRoleController extends BaseController
{
    private String prefix = "order/role";

    @Autowired
    private IOrderRoleService orderRoleService;

    @RequiresPermissions("order:role:view")
    @GetMapping()
    public String role()
    {
        return prefix + "/role";
    }

    /**
     * 查询角色管理列表
     */
    @RequiresPermissions("order:role:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderRole orderRole)
    {
        startPage();
        List<OrderRole> list = orderRoleService.selectOrderRoleList(orderRole);
        return getDataTable(list);
    }

    /**
     * 导出角色管理列表
     */
    @RequiresPermissions("order:role:export")
    @Log(title = "角色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderRole orderRole)
    {
        List<OrderRole> list = orderRoleService.selectOrderRoleList(orderRole);
        ExcelUtil<OrderRole> util = new ExcelUtil<OrderRole>(OrderRole.class);
        return util.exportExcel(list, "role");
    }

    /**
     * 新增角色管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存角色管理
     */
    @RequiresPermissions("order:role:add")
    @Log(title = "角色管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderRole orderRole)
    {
        return toAjax(orderRoleService.insertOrderRole(orderRole));
    }

    /**
     * 修改角色管理
     */
    @GetMapping("/edit/{roleId}")
    public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap)
    {
        OrderRole orderRole = orderRoleService.selectOrderRoleById(roleId);
        mmap.put("orderRole", orderRole);
        return prefix + "/edit";
    }

    /**
     * 修改保存角色管理
     */
    @RequiresPermissions("order:role:edit")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderRole orderRole)
    {
        return toAjax(orderRoleService.updateOrderRole(orderRole));
    }

    /**
     * 删除角色管理
     */
    @RequiresPermissions("order:role:remove")
    @Log(title = "角色管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderRoleService.deleteOrderRoleByIds(ids));
    }
}
